﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SaleOnlineSystem.Admin.Controls
{
    public partial class EditBoxProduct : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ddlCate.Items.Clear();
            DataTable dt = DAL.DCollector.DBCollector.Instance.StoredProcedureSelectWhereByID("tbl_Category", "*", "Category_ID2", 0, "selectwhereid");
            ListItem lt = new ListItem("Chon danh muc", "-1");
            ddlCate.Items.Add(lt);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                lt = new ListItem(dt.Rows[i]["Category_Name"].ToString(), dt.Rows[i]["Category_ID1"].ToString());
                ddlCate.Items.Add(lt);
            }
            ddlCate.SelectedIndex = 0;
            int boxid = Convert.ToInt32(Request.QueryString["boxid"]);
            lblbox.Text = "Chọn danh mục bạn muốn hiển thị ở Box thứ "+boxid;
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (ddlCate.SelectedIndex > 0)
            {
                int boxid = Convert.ToInt32(Request.QueryString["boxid"]);
                int cate1 = Convert.ToInt32(ddlCate.SelectedValue.ToString());
                DAL.DHelpers.Column[] cl = new DAL.DHelpers.Column[3];
                DAL.DCollector.DBCollector.Instance.CallStored("callstored", "Update tbl_BoxProduct set Category_ID1=" + cate1 + "where BoxProduct_ID=" + boxid + "", false);
                Response.Redirect("/Admin/Index.aspx?panel=5&sub=7");
            }
            else
            {
                Response.Write("<script>alert('Bạn vui lòng chọn danh mục sản phẩm...')</script>");
            }
        }
    }
}